# -*- coding: utf-8 -*-
# author yzs
# date 2019-01-14
#
# 无限递归字符串查询
# Description
# Consider a string A = "12345". An infinite string s is built by performing infinite steps on A recursively.
# In i-th step, A is concatenated with ‘$’ i times followed by reverse of A. A=A|$...$|reverse(A),
# where | denotes concatenation.
# Constraints:1<=Q<=10^5, 1<=POS<=10^12
# Input
# 输入第一行为查询次数，后面为每次查询的具体字符位置。
# Output
# 输出每一次查询位置上的字符。
# Sample Input 1 
# 2
# 3
# 10
# Sample Output 1
# 3
# 2


def find_char(s, n):
    if n == 0:
        return -1
    k = 1
    s_len = 11
    loc_add= n
    while s_len < n:
        k += 1
        s_len = 2 * s_len + k
    while loc_add > 11:
        prev_len = (s_len - k) // 2
        if loc_add > prev_len:
            loc_add = loc_add - prev_len
            if loc_add <= k:
                return '$'
            loc_add = loc_add - k
        s_len = prev_len
        k -= 1

    return s[loc_add % 11]


while True:
    try:
        s = "112345$54321"
        t = int(input().strip())
        for i in range(t):
            n = int(input().strip())
            print(find_char(s, n))
    except EOFError:
        break
